﻿using System;
using Xtensive.Orm;

namespace KeyWithTypeId.Model
{
    [HierarchyRoot]
    public class Person : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }

        [Field]
        public Undead UndeadFriend { get; set; }

        public Person(Session session)
            : base(session) {}
    }

    /*
     * By default, DataObjects.Net doesn't not include TypeId into primary key.
     * However, this might help to optimize fetching referenced entities of a deep hierarchy.
     * 
     * See main.cs for demo
     */
    [HierarchyRoot(IncludeTypeId = true)]
    public abstract class Undead : Entity
    {
        [Field, Key]
        public int Id { get; private set; }

        [Field]
        public string Name { get; set; }

        protected Undead(Session session)
            : base(session) { }
    }

    public class Vampire : Undead
    {
        [Field]
        public bool CanBite { get; set; }

        public override string ToString()
        {
            return string.Format("{0}, CanBite: {1}", GetType().Name, CanBite);
        }

        public Vampire(Session session)
            : base(session) {}
    }

    public class Witch : Undead
    {
        [Field]
        public bool CanFly { get; set; }

        public override string ToString()
        {
            return string.Format("{0}, CanFly: {1}", GetType().Name, CanFly);
        }

        public Witch(Session session)
            : base(session) {}
    }

    public class Zombie : Undead
    {
        [Field]
        public bool CanWalk { get; set; }

        public override string ToString()
        {
            return string.Format("{0}, CanWalk: {1}", GetType().Name, CanWalk);
        }

        public Zombie(Session session)
            : base(session)
        {}
    }
}